<?php
//code to show subscriber search.  
echo $this->element('subscriber_search',array('plugin'=>'newsletters'));
?>
<?php
if(!empty($subscribers))
{
	$index->setData($subscribers,'Subscriber');
	
	$index->showFields(array('id','name','email',array('is_register'=>'Registered User')));
	$index->sortablefields(array('id','name'));
	
	$index->setAction(__('View'),'/admin/newsletters/subscribers/view/:Subscriber.id');
	$index->setAction(__('Edit'),'/admin/newsletters/subscribers/edit/:Subscriber.id');
	$index->setAction(__('Delete'),'/admin/newsletters/subscribers/delete/:Subscriber.id',$this->helpers,__('Are you sure you want to delete this subscriber ?'));
	$index->addColumn('is_register','isUserRegistered');
	$index->addColumn('email','formatEmail');
		
	function formatEmail($record)
	{
		uses("Flay");
		$length = 25;
		if(strlen($record['Subscriber']['email']) > $length)
		{
			return substr($record['Subscriber']['email'],0,$length).'...';
		}
		return $record['Subscriber']['email'];
	}
	function isUserRegistered($record)
	{
		if(empty($record['Subscriber']['entity_id']))
		{
			return __('No');
		}
		return __('Yes');	
	}
	$index->setPaginateSeparator(' ');
	echo $index->display();	
}else
{?>
	
	<div class="clear"></div>
	<h4><?php echo __('There is no subscriber!');?></h4>
<?php 
}?>